#!/bin/bash

while :; do
  output=$(docker stats --no-stream --format='{{.ID}};{{.CPUPerc}};{{.MemUsage}}' 2>&1)
  if [[ $? -ne 0 ]]; then
    logger -t webgui "docker stats error: $output"
    exit 1
  fi
  if [[ -n "$output" ]]; then
    curl -sfd "$output" --unix-socket /var/run/nginx.socket http://localhost/pub/dockerload?buffer_length=1 >/dev/null 2>&1
  fi
  sleep 1
done
